import { honor } from "../../../server/api";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    gradelist: [],
    icon: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },
  async getData() {
    const userid = wx.getStorageSync("id");
    const type = 0
    const data = await honor(userid,type);
    if (data.code == 200) {
      const res = data.result.map((item) => {
        const datetime =  item.createTime.split(' ')[0]
        const time = this.formatDateString(datetime)
         item['time'] = time
        switch (item.honor) {
          case "1":
            item["icon"] = "../../../icon/勋章图标/勋章1x280.png";
            break;
          case "2":
            item["icon"] = "../../../icon/勋章图标/勋章2x280.png";
            break;
          case "3":
            item["icon"] = "../../../icon/勋章图标/勋章3x280.png";
            break;
          case "4":
            item["icon"] = "../../../icon/勋章图标/勋章4x280.png";
            break;
          case "5":
            item["icon"] = "../../../icon/勋章图标/勋章5x280.png";
            break;
          case "6":
            item["icon"] = "../../../icon/勋章图标/勋章6x280.png";
            break;
          case "7":
            item["icon"] = "../../../icon/勋章图标/勋章7x280.png";
            break;
          case "8":
            item["icon"] = "../../../icon/勋章图标/勋章8x280.png";
            break;
          case "9":
            item["icon"] = "../../../icon/勋章图标/勋章9x280.png";
            break;
          case "10":
            item["icon"] = "../../../icon/勋章图标/勋章10x280.png";
            break;
          default:
            break;
        }
        return item;
      });
      this.setData({ gradelist: res });
    }
  },
  formatDateString(dateStr) {
    const regex = /-/g; // 匹配所有的连字符
    const parts = dateStr.split(regex); // 将字符串按连字符分割成数组
    const year = parts[0];
    const month = parts[1];
    const day = parts[2];
    return `${year}年${month}月${day}日`; // 使用模板字符串拼接新格式
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
